package com.ssyan.factory.simplefactory.order;

import com.ssyan.factory.simplefactory.CheesePizza;
import com.ssyan.factory.simplefactory.GreekPizza;
import com.ssyan.factory.simplefactory.PepperPizza;
import com.ssyan.factory.simplefactory.Pizza;

/**
 * @author ssyan
 * @Description 简单工厂类，对外统一提供对象
 * @create 2021/8/27 22:42
 * @Version 1.0
 */

//简单工厂类
public class SimpleFactory {

    //根据orderType 返回对应的Pizza对象
    //简单工厂模式，也叫静态工厂模式
    public static Pizza createPizza(String orderType) {
        Pizza pizza = null;
        System.out.println("使用简单工厂模式");
        if (orderType.equals("greek")) {
            pizza = new GreekPizza();
        } else if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
        } else if (orderType.equals("pepper")) {
            pizza = new PepperPizza();
        }
        return pizza;
    }
}
